﻿<script>
    var _sorts = @this.RawSerialize(this.ViewBag.ListSort);
    var _sorts2 = @this.RawSerialize(this.ViewBag.SortList);
    var _sts = [{ id: "0", text: "下线" }, { id: "1", text: "上线" }];
    var _lives = [{ id: "0", text: "否" }, { id: "1", text: "是" }];
    var _file_domain = "@ViewBag.FileDomain";
   



    var _vm;
    $(function () {
        var vm = new PageViewModel();
        _vm = vm;
        ko.applyBindings(vm);
        vm.init();

    });
 

    function PageViewModel()
    {
        var me = this;
        ViewModel.call(me);
        vmExtend.call(me);

        me.url = "/Wiki/Video/Models";
        me.deleteUrl = "/Wiki/Video/Delete";

        
        me.dialog = new FormDialog(me);
         
    }
    function vmExtend() {
        var me = this;
    }


    function FormDialog(vm) {
        var me = this;
        Dialog.call(me);

        me.onOpen = function () {
             
            var model = me.editModel();
            if (model) {
                var bindModel = $ko.toJS(model);
                me.model(bindModel);
                 
            }
            else
            {  
            }
        }

        me.onSave = function () {
            if (!$('#form1').formValid()) {
                return false;
            }

            var model = me.model();

            if (me.editModel()) {
                model.ImageUrl = $("#ImageUrl").val();   
                model.FileUrl = $("#FileUrl").val();   
                $ace.post("/Wiki/Video/Edit", model, function (result)
                {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.dataTable.reload();
                    //setTimeout(function () { window.location.reload(); }, 1000);
                }
                );
            }
            else {
                model.ImageUrl = $("#ImageUrl").val();
                model.FileUrl = $("#FileUrl").val();   
                $ace.post("/Wiki/Video/Add", model, function (result)
                {
                    $ace.msg(result.Msg);
                    me.close();
                    vm.loadData();
                    //setTimeout(function () { window.location.reload(); }, 1000);
                }
                );
            }
        }
    }

</script>
